<template>
  <div class="mui-numbox" data-numbox-min="1" >
    <button class="mui-btn mui-btn-numbox-minus" type="button">-</button>
    <input id="test" class="mui-input-numbox" type="number" value="1" @change="changeCount" ref="numbox"/>
    <button class="mui-btn mui-btn-numbox-plus" type="button">+</button>
  </div>
</template>

<script>
import mui from "../../lib/mui/js/mui.min.js";
export default {
    mounted(){
        //初始化数字选择框 mui(Selector).numbox()
        mui(".mui-numbox").numbox();
    },
    methods:{
      changeCount(){
        //每当文本框的数值被改变后，立即通过事件调用机制，把值通过参数传递出去
        // console.log(this);
        // console.log(this.$refs.numbox.value);
        this.$emit("getCont",parseInt(this.$refs.numbox.value));
      }
    },
    props:["max"],
    watch:{
      // 通过watch属性监听，来获取一个合法有效的max值
      "max" : function(newVal,oldVal){
        //使用js API 来设置最大值
        mui(".mui-numbox").numbox().setOption('max',newVal);
      }
    }
};
</script>

<style lang="scss" scoped>
</style>